<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var str= "abcc"
        var longestPalindrome = function (s) {
                answer = []
                answerxx = []
                big=0
                pos = 0
                for (var i = 0; i < s.length - 1; i++) {
                    if (s[i] == s[i + 2]) {
                        answer.push(i + 1)
                    } else if (s[i] == s[i + 1]) {
                        answerxx.push(i)
                    }
                }
                console.log(answer)
                console.log(answerxx)
                for(var i in answer){
                    now  = expose(answer[i])
                    if(now[0]>big){
                        big = now[0]
                        pos = now[1]
                    }
                }
                for(var i in answerxx){
                    now  = exposex(answerxx[i])
                    if(now[0]>big){
                        big = now[0]
                        pos = now[1]
                    }
                }
                function expose(index){
                    count = 3
                    sign = true
                    left = index-1
                    right = index+1
                    while(sign){
                        left--
                        right++
                        if(s[left]==s[right]){
                            count+=2
                        }else{
                            sign=false
                        }

                    }
                    return [count,left]
                }
                function exposex(index){
                    count = 2
                    sign = true
                    left = index
                    right = index+1
                    while(sign){
                        left--
                        right++
                        if(s[left]==s[right]){
                            count+=2
                        }else{
                            sign=false
                        }

                    }
                    return [count,left+1]
                }
                return s.substr(pos,big)
            };
            var c = longestPalindrome(str)
    </script>
</body>
</html>